﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>单据列表</title>
    <link href="../Scripts/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="../Scripts/bootstrap/css/bootstrap.css" rel="stylesheet" />
    <link href="../Scripts/bootstrap/bootstrap-table/src/bootstrap-table.css" rel="stylesheet"
          type="text/css" />
    <link href="../Scripts/bootstrap/css/style.min.css" rel="stylesheet" type="text/css"
          media="all" />

    <!--jquery-->
    <script src="../Scripts/jquery-1.11.0.min.js" type="text/javascript"></script>
    <script src="../Scripts/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
    <script src="../Comm/JS/layer/layer.js" type="text/javascript"></script>
    <link href="../Comm/JS/layer/layer.css" rel="stylesheet" type="text/css" />
    <!--bootstrap-table-->
    <script src="../Scripts/bootstrap/bootstrap-table/src/bootstrap-table.js" type="text/javascript"></script>
    <script src="../Scripts/bootstrap/bootstrap-table/src/locale/bootstrap-table-zh-CN.js"
            type="text/javascript"></script>
    <script src="../Scripts/bootstrap/BootstrapUIDialog.js" type="text/javascript"></script>
    <script src="../Scripts/bootstrap/bootstrap-paginator/js/bootstrap-paginator.js"
            type="text/javascript"></script>
    <script src="../Scripts/bootstrap/bootstrap-table/src/colResizable-1.6.min.js"></script>
    <script src="../Scripts/bootstrap/bootstrap-table/src/extensions/resizable/bootstrap-table-resizable.js"></script>
    <!--公共JS-->
    <script src="../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../Scripts/config.js" type="text/javascript"></script>
    <script src="../Comm/Gener.js" type="text/javascript"></script>
    <script language="JavaScript" src="../Comm/JScript.js" type="text/javascript"></script>
    <script src="../Comm/JS/Calendar/WdatePicker.js" type="text/javascript"></script>
    <link href="../Comm/JS/Calendar/skin/WdatePicker.css" rel="stylesheet" type="text/css" />

    <link href="../Comm/Style/Search.css" rel="stylesheet" />
    <script type="text/javascript">

        var webUser = null;
        var frmBill = null;
        var frmID;
        var ur;//当前用户的查询信息
        var pageIdx = 1;
        var fields = []; //字符型字段查询的集合

        //分页信息
        var count = 0;//总条数
        var pageSize = 10;//一页10条
        var pages = 1; //总页数

        var firstLoadTable = false;

        //初始化页面
        $(function () {
            InitPage();
        });
        function InitPage() {
            webUser = new WebUser();
            if (webUser.No == null)
                return;

            frmID = GetQueryString("FrmID");

            pageIdx = GetQueryString("PageIdx");//当前页

            frmBill = new Entity("BP.Frm.FrmBill", frmID);
            document.title = frmBill.Name;

            //当前用户查询信息.
            ur = new Entity("BP.Sys.UserRegedit");
            ur.MyPK = webUser.No + "_" + frmID + "_SearchAttrs";
            ur.RetrieveFromDBSources();
            ur.OrderBy = "";
            ur.OrderWay = "";
            ur.Update();
            //初始化查询条件
            if (Init_ToolBar() == false) {
                $("#toolBar").html(webUser.Name + "没有查询权限");
                return;
            }
            pageSize = ur.GetPara("PageSize");
            if (pageSize == "" || pageSize == undefined)
                pageSize = "10";


            //显示查询数据
            BindTable();

            $("td").on("mouseover", function () {
                if (this.offsetWidth < this.scrollWidth) {
                    var that = this;
                    var text = $(this).text();
                    layer.tips(text, that, {
                        tips: 1,
                        time: 0
                    });
                }
            });
            $("td").on("mouseout", function () {
                layer.closeAll();
            });

            if (pageIdx == null || pageIdx == undefined || pageIdx == "")
                pageIdx = 1;
            //分页
            Paginator(pages, pageIdx);
        };


        function Init_ToolBar() {
            var handler = new HttpHandler("BP.Frm.WF_CCBill_API");
            handler.AddPara("FrmID", frmID);
            var powerData = handler.DoMethodReturnString("CCFrom_FrmPower");
            if (powerData.indexOf("err@") != -1) {
                alert(powerData);
                return;
            }
            powerData = JSON.parse(powerData);
            if (parseInt(powerData.IsView) == 0)
                return false;


            handler = new HttpHandler("BP.Frm.WF_CCBill");
            handler.AddPara("FrmID", frmID);
            var data = handler.DoMethodReturnString("Search_ToolBar");
            if (data.indexOf('err@') == 0) {
                alert(data);
                $("#Msg").html(data);
                return;
            }
            var data = JSON.parse(data);

            //单据表单属性
            var mapData = data.Sys_MapData;
            var attrs = data.Attrs;

            var html = "";

            

            html += "<tr>";
            var atPara = mapData[0].AtPara;

            var count = 0;//计算是否换行

            var stringSearchKeys = GetPara(atPara, "RptStringSearchKeys");
            if (stringSearchKeys != null && stringSearchKeys != undefined && stringSearchKeys != "") {
                var strs = stringSearchKeys.split("*");
                var fieldV=""
                $.each(strs, function (i, str) {
                    if (str != "") {
                        var item = str.split(",");
                        fieldV = ur.GetPara(item[0]);
                        if (fieldV == null || fieldV == undefined)
                            fieldV = "";
                        if (item.length == 2) {
                            
                            fields.push(item[0]);
                             html +="<td><label  style='text-align: right; margin-top:5px;margin-left:5px;' for='TB_"+item[0]+"'>" + item[1] + ":&nbsp;&nbsp</label></td>"
                             html += "<td align='left'><input style='width:100%;' type=text id='TB_"+item[0]+"'  name='TB_"+item[0]+"' value='" + fieldV + "' class='form-control' /></td>";
                            count++;
                            if (count == 4) {
                                html += "</tr>";
                                html += "<tr>";
                                count = 0;
                            }
                        }
                    }
                });
               

            }else if (GetPara(atPara, "IsSearchKey") == "1") {

                var keyLabel = GetPara(atPara, "DTSearchLabel");
                var keyLabel = "关键字";
                html +="<td><label  style='text-align: right; margin-top:5px;margin-left:5px;' for='TB_Key'>" + keyLabel + ":&nbsp;&nbsp</label></td>"
                html += "<td align='left'><input style='width:100%;' type=text id='TB_Key' placeholder='请输入关键字...' name='TB_Key' value='" + ur.SearchKey + "' class='form-control' /></td>";
                count++;
            }

            if (GetPara(atPara, "DTSearchWay") != "0") {

                var dtFrom = GetPara(atPara, "DTSearchLabel");
                if (dtFrom == undefined)
                    dtFrom = '日期从';

                html += "<td align='right'><label style='text-align: right; margin-top:5px;padding-left:20px;'>" + dtFrom + ":</label></td>";

                if (GetPara(atPara, "DTSearchWay") == "1") {
                    html += "<td align='left' style='width:120px'><input type=text id='TB_DTFrom' name='TB_DTFrom' value='" + ur.DTFrom + "'  onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd'})\" style='width:120px;' class='form-control Wdate' /></td>";
                    html += "<td align='right'><label>到&nbsp;&nbsp;</label></td><td align='left'><input type=text id='TB_DTTo' name='TB_DTTo' value='" + ur.DTTo + "' onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd'})\" style='width:120px;' class='form-control Wdate' /></td>";
                } else {
                    html += "<td align='left' style='width:160px'><input type=text id='TB_DTFrom' name='TB_DTFrom' value='" + ur.DTFrom + "'  onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'});\" style='width:160px;' class='form-control Wdate' /></td>";
                    html += "<td align='right'><label>到&nbsp;&nbsp;</label></td><td align='left'><input type=text id='TB_DTTo' name='TB_DTTo' value='" + ur.DTTo + "' onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'});\"  style='width:160px;' class='form-control Wdate' /></td>";
                }
                count = count+2
                if (count == 4 || count > 4) {
                    html += "</tr>";
                    html += "<tr>";
                    count = 0;
                }
            }

           
            //增加外键
            for (var i = 0; i < attrs.length; i++) {
                var attr = attrs[i];
                var W = attr.Width;
                if (attr.Width >= 1000) {
                    html += "</tr>";
                    html += "<tr>";
                    W = 130;
                }
                html += "<td align='right'><label style='text-align: right; margin-top:5px;margin-left:5px;' for='DDL_" + attr.Field + "'>" + attr.Name + ":</label></td>";
                html += "<td align='left'><select class='form-control' style='margin-top:5px;width:100%;' name='DDL_" + attr.Field + "' ID='DDL_" + attr.Field + "'>" + InitDDLOperation(data, attr, "all") + "</select></td>";
                count++
                if (count == 4) {
                    html += "</tr>";
                    html += "<tr>";
                    count = 0;
                }
            }
            

            //增加按钮.
            html += '<td align="left" colspan=2 style="padding-top:4px"><a href="#"class="btn btn-primary btn-sm" style="margin-left:20px" id="Btn_Search" onclick="Search()">查询</a>  ';

            //获得配置的按钮.
            var fb = new Entity("BP.Frm.FrmBill", frmID);

            if (fb.BtnNewLable == "") fb.BtnNewLable = "新建";
            if (fb.BtnDelLable == "") fb.BtnDelLable = "删除";
            if (fb.BtnImpExcel == "") fb.BtnImpExcel = "导入";
            if (fb.BtnExpExcel == "") fb.BtnExpExcel = "导出";
            if (fb.BtnGroupLabel == "") fb.BtnGroupLabel = "分析";

            

            //权限判断按钮.
            if (parseInt(powerData.IsInsert) == 1)
                html += '&nbsp;<a href="#" class="btn btn-default btn-sm" id="Btn_New" onclick="New()">' + fb.BtnNewLable + '</a>';

            if (parseInt(powerData.IsDelete) == 1)
                html += '&nbsp;<a href="#" class="btn btn-default btn-sm" id="Btn_Del" onclick="javascript:Delete();">' + fb.BtnDelLable + '</a>';

            if (fb.BtnImpExcelEnable == 1)
                html += '&nbsp;<a href="#" class="btn btn-default btn-sm" id="Btn_Imp" onclick="Imp()">' + fb.BtnImpExcel + '</a> ';

            if (fb.BtnExpExcelEnable == 1)
                html += '&nbsp;<a href="#" class="btn btn-default btn-sm" id="Btn_ExpExcel" onclick="ExpExcel()">' + fb.BtnExpExcel + '</a>';

            if (fb.BtnGroupEnable == 1)
                html += '&nbsp;<a href="#" class="btn btn-default btn-sm" id="Btn_Group" onclick="Group()">' + fb.BtnGroupLabel + '</a>';


            //增加方法.
            //获得当前的集合.
            var fms = new Entities("BP.Frm.Methods", "FrmID", frmID);
            for (var i = 0; i < fms.length; i++) {
                var fm = fms[i];
                if (fm.IsSearchBar != 1)
                    continue;

                html += "<input type='button' value='" + fm.MethodName + "' id='Btn_" + fm.MethodID + "' onclick=\"Done('" + fm.WarningMsg + "','" + fm.MyPK + "');\" />";
            }


            html += "</td></tr>";

            html += "</table>";

            $("#toolBar").append(html);

            //为查询外键赋值.
            //格式为: @WFSta=0@FK_Dept=02
            var json = AtParaToJson(ur.Vals);
            for (var i = 0; i < attrs.length; i++) {
                var attr = attrs[i];
                var selectVal = json[attr.Field];

                if ((selectVal == undefined || selectVal == "") && attr.Field!="FK_Dept")
                    $("#DDL_" + attr.Field).val("all");
                else
                    $("#DDL_" + attr.Field).val(selectVal);
            }

            return true;
        }

        //初始化下拉列表框的OPERATION
        function InitDDLOperation(frmData, mapAttr, defVal) {

            var operations = "";
            if (mapAttr.Field!="FK_Dept")
                operations += "<option value='all' >全部</option>";

            var ens = frmData[mapAttr.Field];
            if (ens == null) {
                ens = [{ 'IntKey': 0, 'Lab': '否' }, { 'IntKey': 1, 'Lab': '是' }];
            }
            for (var i = 0; i < ens.length; i++) {

                var en = ens[i];

                if (en.No == undefined)
                    operations += "<option value='" + en.IntKey + "'>" + en.Lab + "</option>";
                else
                    operations += "<option value='" + en.No + "'>" + en.Name + "</option>";
            }
            return operations;
        }


        //执行查询.
        function Search() {

            //保存查询条件.

            ur = new Entity("BP.Sys.UserRegedit");
            ur.MyPK = webUser.No + "_" + frmID + "_SearchAttrs";
            ur.FK_Emp = webUser.No;

            if ($("#TB_Key") != null && $("#TB_Key").val() != "" && fields.length==0)
                ur.SearchKey = $("#TB_Key").val();
            else
                ur.SearchKey = "";

            //设置查询时间.
            if ($("#TB_DTFrom").length == 1)
                ur.DTFrom = $("#TB_DTFrom").val();

            if ($("#TB_DTTo").length == 1)
                ur.DTTo = $("#TB_DTTo").val();

            //获得外键的查询条件,存储里面去.
            var str = "";
            $("select[name^='DDL_']").each(function () {
                var id = $(this).attr("id");
                id = id.replace("DDL_", "");
                str += "@" + id + "=" + $(this).val();
            });

            //增加字段查询
            for (var i = 0; i < fields.length; i++) {
                var field = fields[i];
                var strs = $("input[name='TB_" + field + "']");
                if (strs.length == 1) {
                    ur.SetPara(field, $("#TB_" + field).val());
                } else {
                    if ($("#TB_" + field + "_0").val() == "" && $("#TB_" + field + "_1").val() == "")
                        ur.SetPara(field, "");
                    else
                        ur.SetPara(field, $("#TB_" + field+"_0").val()+","+$("#TB_" + field+"_1").val());
                }
            }

            ur.FK_Emp = webUser.No;
            ur.CfgKey = "SearchAttrs";
            ur.Vals = str;
            ur.FK_MapData = frmID;
            ur.SetPara("RecCount", count);
            var i = ur.Save();

            var url = window.location.href;
            if (url.indexOf("PageIdx") != -1)
                url = replaceParamVal(url, "PageIdx", 1);

            SearchData();
            pageIdx = 1;
            Paginator(pages, pageIdx);
        }


        function SearchData(orderBy, orderWay) {

            //创建处理器.
            var handler = new HttpHandler("BP.Frm.WF_CCBill");
            handler.AddUrlData()
            handler.AddPara("PageIdx", pageIdx);
            handler.AddPara("PageSize", pageSize);
            if (orderBy != null && orderBy != undefined)
                ur.OrderBy = orderBy;
            if (orderWay != null && orderWay != undefined)
                ur.OrderWay = orderWay;

            if ($("#DDL_FK_Dept").length == 1) {
                ur.Vals = ur.Vals + "@FK_Dept=" + $("#DDL_FK_Dept").val();
            }
            ur.Update();

           

            //查询集合
            var data = handler.DoMethodReturnString("Search_Init");
            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }

            data = JSON.parse(data);

            ur = new Entity("BP.Sys.UserRegedit");
            ur.MyPK = webUser.No + "_" + frmID + "_SearchAttrs";
            ur.RetrieveFromDBSources();


            count = ur.GetPara("RecCount");
            if (count % pageSize != 0)
                pages = parseInt(count / pageSize) + 1;
            else
                pages = parseInt(count / pageSize);

            if (pages == 0) pages = 1;

            if (firstLoadTable) {
                $('#dg').bootstrapTable("load", data["DT"]);
                return ;
            }

            //设置查询总数居的合计、平均等信息
            var heji = data["Search_FieldSet"];
            var _html = "";
            if (heji != null && heji != undefined) {
                $.each(heji, function (i, item) {
                    var val = item.Value;
                    if (val == null || val == "" || val == undefined)
                        val = 0;
                    if (item.Type == "Sum")
                        _html += item.Field + "总合计：" + val + " ";
                    if (item.Type == "Avg")
                        _html += item.Field + "总平均：" + val + " ";
                });
            }

            $("#FieldSet").html("").html(_html);
            return data;
        }

        //生成查询页面..
        function BindTable() {

            //获取页面的高度
            var H = document.body.clientHeight;
            var tableH = H - $("#toolbar").outerHeight() - $("#page-nav").outerHeight() - 70;

            if (pageIdx == "" || pageIdx == undefined)
                pageIdx = "1";
            

            var mapdata = SearchData();
            var attrs = mapdata["Attrs"];

            if (attrs == undefined) {
                alert('没有取得属性.');
                return;
            }

            var keyOfEn = "";
            var sortColumns = frmBill.SortColumns; //排序字段
            var columns = new Array();;
            columns.push({
                title: '序',
                field: '',
                align: 'center',
                width: 25,

                formatter: function (value, row, index) {
                    return pageSize * (pageIdx - 1) + index + 1;    // 返回每条的序号： 每页条数 *（当前页 - 1 ）+ 序号
                }
            });

            //颜色设置
            var colorSet = frmBill.ColorSet;

            for (var i = 0; i < attrs.length; i++) {
                var attr = attrs[i];

                if (attr.UIVisible == 0
                    || attr.KeyOfEn == "OID"
                    || attr.KeyOfEn == "WorkID"
                    || attr.KeyOfEn == "NodeID"
                    || attr.KeyOfEn == "MyNum"
                    || attr.KeyOfEn == "MyPK") {
                    keyOfEn = attr.KeyOfEn
                    continue;
                }


                var field = attr.KeyOfEn;
                var title = attr.Name;
                var width = attr.Width;
                var sortable = true;
                if (sortColumns != null && sortColumns != "")
                    sortable = sortColumns.indexOf(field) != -1 ? true : false;

                if (field == "BillState") {
                    columns.push({
                        field: field,
                        title: title,
                        width: attr.Width,
                        fixed: false,
                        sortable: sortable,
                        formatter: function (value, row, index) {
                            return GetBillState(value);
                        }
                    });
                    continue;
                }

                if (field == "Title") {
                    columns.push({
                        field: field,
                        title: title,
                        width: attr.Width,
                        fixed: false,
                        sortable: sortable,
                        formatter: function (value, row, index) {
                            var icon = GenerICON(false, row.BillState);
                            return "<a href=\"javascript:OpenIt('" + row.OID + "','" + frmID + "','" + 0 + "',' ','" + webUser.No + "','" + row.BillState + "',)\"><img src=" + icon + " border=0 width='14px;' />" + value + "</a>";
                        }
                    });
                    continue;
                }

                if (attr.UIContralType == 1 || attr.UIContralType == 3 || GetPara(attr.AtPara, "MultipleChoiceSmall") == "1") {
                    if (width == null || width == "" || width == undefined)
                        width = 180;
                    //if (attr.LGType == 0)
                    //    field = field + "T";
                    //else
                    //    field = field + "Text";

                    columns.push({
                        field: field,
                        title: title,
                        fixed: false,
                        width: width,
                        sortable: sortable,
                        cellStyle: {
                            css: { "white-space": "nowrap", "word-break": "keep-all", "width": "100%" }
                        },
                        formatter: function (value, row, index) {
                            var val = row[this.field + "Text"];
                            if (val == undefined || val == null)
                                val = row[this.field + "T"];
                           
                            if (val == undefined || val == null)
                                return value;
                            else
                                return val;
                        }
                    });
                    continue;
                }
                if (attr.UIContralType == 2) {
                    columns.push({
                        field: field,
                        title: title,
                        width: attr.Width,
                        fixed: false,
                        sortable: sortable,
                        formatter: function (value, row, index) {
                            if (value == "0") return "否";
                            if (value == "1") return "是";
                        }
                    });
                    continue;
                }


                if (width == null || width == "" || width == undefined)
                    width = 100;

                columns.push({
                    field: field,
                    title: title,
                    width: attr.Width,
                    fixed: false,
                    sortable: sortable,
                    formatter: function (value, row, index) {
                        var fieldColor = [];
                        if (colorSet.indexOf("@" + this.field + ":") != -1) {
                            fieldColor = getFieldColor(colorSet, this.field);
                        }
                        if (fieldColor.length == 0)
                            return value;
                        for (var i = 0; i < fieldColor.length; i++) {
                            var color = fieldColor[i];
                            if (color.From <= value && color.To >= value)
                                return "<div style='width:20px;height:20px;text-align:center;background:" + color.Color + "'>" + value + "</div>";
                        }
                    }

                });
            }
            //加入操作下载文件
            columns.push({
                field: 'oper',
                title: '操作',
                width: 80,
                align: 'center',
                formatter: function (value, row, index) {
                    var _Html = "";
                    //删除规则
                    var deleteWay = frmBill.GetPara("DeleteMyDept");
                    var starter = row["Starter"];
                    var IsDelete = false;
                    if (deleteWay == "1") { //可以删除我本部门人员编辑创建的数据
                        var depts = new Entities("BP.GPM.DeptEmps");
                        depts.Retrieve("FK_Dept", webUser.FK_Dept, "FK_Emp", starter);
                        if (depts.length > 0)
                            IsDelete = true;
                    }
                    if (deleteWay != "1" && webUser.No == starter) //只能删除自己创建的
                        IsDelete = true;

                    if (IsDelete == true)
                        _Html += '<a href="javaScript:void(0);" onclick="Delete(' + row["OID"] + ',\'' + frmID + '\')"><i class="glyphicon glyphicon-trash"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;';//删除
                    _Html += '<a href="javaScript:void(0);" onclick="OpenIt(' + row["OID"] + ',\'' + frmID + '\','+row["BillState"]+')"><i class="glyphicon glyphicon-edit"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;';//查看
                    _Html += '<a href="javaScript:void(0);" onclick="CopyBill(' + row["OID"] + ',\'' + frmID + '\')"><i class="glyphicon glyphicon-random"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;';//复制
                    return _Html;
                }
            });
            //var url = "../";
            $('#dg').html("");
            $('#dg').bootstrapTable({
                data: mapdata["DT"],
                columns: [columns],
                cache: false,
                striped: true,
                height: tableH,
                singleSelect: true,
                clickToSelect: true,

                maintainSelected: true,
                sidePagination: "client",
                pageNumber: 1,
                strictSearch: true,
                onSort: function (name, order) {
                    pageIdx = 1;
                    SearchData(name, order);
                    Paginator(pages, 1)
                },
                //得到查询的参数
                queryParams: function (params) {
                    //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    var temp = {
                        rows: 10,                         //页面大小
                        page: (count / 10) + 1,   //页码

                    };
                    return temp;
                },
                onClickRow: function (row, $element) {
                    $('.info').removeClass('info');

                    $($element).addClass('info').attr("data-val", row.OID);
                },
                onDblClickRow: function (row, $element) {
                    var pkval = row["OID"];
                    var paras = "&OID" + "=" + pkval;
                    for (var i = 0; i < attrs.length; i++) {
                        var attr = attrs[i];
                        if (attr.UIContralType == 1)
                            paras += "&" + attr.KeyOfEn + "=" + row[attr.KeyOfEn];
                    }

                    OpenIt(pkval, frmID,row["BillState"]);
                }

            });
            $("#dg").colResizable({
                liveDrag: true,
                gripInnerHtml: "<div class='grip'></div>",
                draggingClass: "dragging",
                resizeMode: 'fit',
                //拖动事件
                onDrag: function () {
                    $('#dg').bootstrapTable("resetView")
                }
            });

            firstLoadTable = true;

        }


        function customSort(sortName, sortOrder, data) {
            var order = sortOrder === 'desc' ? -1 : 1
            data.sort(function (a, b) {
                var v1 = a[sortName]
                var v2 = b[sortName]
                if (v1 == 3) {
                    return -1;
                }
                if (v1 > v2) {
                    return 1
                }
                return 0
            })
        }
        //分页功能
        function Paginator(pageCount, currentPage) {
            var selects = "<Select id='DDL_PageSize' onchange='changePageSie()' style='min-width: 40px !important; width: 50px;' class='form-control'><option value=5>5</option><option value=10>10</option><option value=15>15</option><option value=20>20</option><option value=25>25</option></Select>";
            var pageCount = pageCount; //取到pageCount的值(把返回数据转成object类型)
            var options = {
                bootstrapMajorVersion: 3, //版本
                currentPage: currentPage, //当前页数
                totalPages: pageCount, //总页数
                shouldShowPage: true, //是否显示该按钮
                itemTexts: function (type, page, current) {
                    switch (type) {
                        case "first":
                            return "首页";
                        case "prev":
                            return "上一页";
                        case "next":
                            return "下一页";
                        case "last":
                            return "末页";
                        case "page":
                            return page;
                    }
                }, //点击事件，用于通过Ajax来刷新整个list列表
                onPageClicked: function (event, originalEvent, type, page) {
                    pageIdx = page;
                    SearchData();
                    $('#page_info').html("").append("<li class='disabled controls'>" +selects+"当前第" + pageIdx + "页，总共" + pages +
                        "页,总共" + count + "条记录。</li>");
                }
            };
            $('#page_nav').bootstrapPaginator(options);
            $('#page_info').html("").append("<li class='disabled controls'>" +selects+"当前第" + pageIdx + "页，总共" + pages +
                "页,总共" + count + "条记录。</li>");

            $("#DDL_PageSize").val(pageSize);

        }


        function changePageSie() {
            pageSize = $("#DDL_PageSize").val();
            ur = new Entity("BP.Sys.UserRegedit");
            ur.MyPK = webUser.No + "_" + frmID + "_SearchAttrs";
            ur.RetrieveFromDBSources();
            ur.SetPara("PageSize", pageSize);
            ur.Update();

            pageIdx = 1;
            SearchData();
            Paginator(pages, pageIdx);
        }

        function Exp() {
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Comm");
            handler.AddPara("EnsName", GetQueryString("EnsName"));
            //查询集合
            var data = handler.DoMethodReturnString("Search_Exp");
            var url = "";
            if (data.indexOf('err@') == 0) {
                alert(data);
            }
            if (plant != 'CCFlow') {
                var currentPath = window.document.location.href;
                var path = currentPath.substring(0, currentPath.indexOf('/WF') + 1);
                data = path + data;
            }
            window.open(data);
            return;

        }



        function New() {

            var frmID = GetQueryString("FrmID");
            var handler = new HttpHandler("BP.Frm.WF_CCBill");
            handler.AddUrlData();
            var workID = handler.DoMethodReturnString("MyBill_CreateBlankBillID");
            OpenIt(workID, frmID);

            return;

        }

        function Delete(workid) {
            if (workid == null || workid == undefined || workid == "") {

                //删除选中的行
                var workid = $('.info').attr('data-val');

                if (workid == "") {
                    alert("没有选择行，不能删除");
                    return;
                }

            }
            if (confirm("您确定要删除吗？") == false)
                return;
            var handler = new HttpHandler("BP.Frm.WF_CCBill");
            handler.AddPara("FrmID", GetQueryString("FrmID"));
            handler.AddPara("WorkID", workid);
            var data = handler.DoMethodReturnString("MyBill_Delete");

            if (data.indexOf('err@') == 0) {
                alert(data);
            }

            window.location.reload();
        }
        function GenerColor(BillState, isCanDo) {

            if (BillState == 100) {
                return "green";
            }

            if (BillState == 1) {
                return "yellow";
            }
            return "";
        }

        function GetBillState(BillState, isCanDo) {
            if (BillState == 0)
                return "空白";

            if (BillState == 1)
                return "草稿";

            if (BillState == 2)
                return "编辑中";

            if (BillState == 100)
                return "归档";

            return BillState;
        }
        function GenerICON(isCanDo, BillState) {

            if (BillState == 3)
                icon = "./Img/BillState/Complete.png";  //已经完成.
            else if (BillState == 2)
                icon = "./Img/BillState/Runing.png"; //运行中.
            else if (BillState == 5)
                icon = "./Img/BillState/ReturnSta.png"; //退回.
            else
                icon = "./Img/BillState/Etc.png"; //其他.

            if (isCanDo == true && BillState != 3)
                icon = "./Img/BillState/Todo.png"; //其他.

            return icon;
        }

        function OpenIt(workid, frmID, billstate) {
            var IsReadonly = "0";
            if (billstate != null && billstate != undefined && billstate ==100)
                IsReadonly="1"
            //RowOpenModel  0=新窗口打开 1=在本窗口打开 2=弹出窗口打开,关闭后不刷新列表 3=弹出窗口打开,关闭
            var rowOpenModel = parseInt(frmBill.RowOpenModel);
            var url = "";
            url = "MyBill.htm?WorkID=" + workid + "&FrmID=" + frmID + "&FK_MapData=" + frmID + "&IsReadonly=" + IsReadonly;
            if (rowOpenModel == 0)
                window.open(url);
            if (rowOpenModel == 1)
                window.location.href = url;
            if (rowOpenModel == 2) {
                var W = document.body.clientWidth - 40;
                var H = document.body.clientHeight - 40;

                OpenBootStrapModal(url, "eudlgframe", frmBill.Name, W, H, "icon-property", null, null, null, null, null, "black");
            }
            if (rowOpenModel == 3) {
                var W = document.body.clientWidth - 40;
                var H = document.body.clientHeight - 40;
                OpenBootStrapModal(url, "eudlgframe", frmBill.Name, W, H, "icon-property", null, null, null, function () {
                    window.location.href = window.location.href;
                }, null, "black");
            }

            return;

        }


        /**
         * 获取字段的设置
         * @param colorSet  颜色总体设置
         * @param keyOfEn 字段
         */
        function getFieldColor(colorSet, keyOfEn) {
            var fieldColor = [];
            var colorSets = colorSet.split('@');
            for (var i = 0; i < colorSets.length; i++) {
                if (colorSets[i] == "")
                    continue;
                var strs = colorSets[i].split(':');
                if (strs.length == 0 || strs.length == 1)
                    continue;
                if (strs[0] != keyOfEn)
                    continue;
                var ss = strs[1].split(';');
                for (var k = 0; k < ss.length; k++) {
                    if (ss[k] == "")
                        continue;
                    var ts = ss[k].split(',');
                    if (ts.length < 3) {
                        alert('字段' + keyOfEn + '范围颜色设置格式错误');
                        break;
                    }

                    fieldColor.push({
                        "From": parseInt(ts[0].replace("From=", "")),
                        "To": parseInt(ts[1].replace("To=", "")),
                        "Color": ts[2].replace("Color=", "")
                    });
                }



            }
            return fieldColor;
        }

        //复制一条数据 //创建新的workid 复制从表、附件
        function CopyBill(workid, frmID) {
            var handler = new HttpHandler("BP.Frm.WF_CCBill");
            handler.AddPara("FrmID", frmID);
            handler.AddPara("WorkID", workid);
            var data = handler.DoMethodReturnString("MyBill_Copy");
            if (data.indexOf("err@") != -1) {
                alert(data);
                return;
            }
            SearchData();
            pageIdx = 1;
            Paginator(pages, pageIdx);

        }

        ///导入.
        function Imp() {
            var url = "./Opt/Imp.htm?FrmID=" + GetQueryString("FrmID") + "&EntityType=2";
            window.location.href = url;
        }

        //导出
        function ExpExcel() {
            var handler = new HttpHandler("BP.Frm.WF_CCBill");
            handler.AddPara("FrmID", frmID);
            //查询集合
            var data = handler.DoMethodReturnString("Search_Exp");
            var url = "";
            if (data.indexOf('err@') == 0) {
                alert(data);
            }

            data = basePath + data;

            window.open(data);
            return;
        }


        function Group() {
            var url = "Group.htm?FrmID=" + GetQueryString("FrmID");
            window.location.href = url;
        }
    </script>

</head>
<body id="SearchHtml" class="cs-search-html">
    <div class="wrapper wrapper-content animated fadeInRight cs-table" style="padding: 0px 10px 0px 10px">
        <div class="ibox-content">
            <div class="row cs-shadow-box">
                <div class="panel panel-default" style="border: 0px; margin-bottom: 3px">
                    <div id="toolBar" style="width: 100%">
                    </div>
                </div>
            </div>
            <div class="row cs-shadow-box">
                <table id="dg" class="table table-hover JColResizer" style="word-wrap: break-word; word-break: break-all;">
                </table>
                <!-- 显示分页信息 -->
                <div>
                    <div class="row cs-pagination" style="float:left;width:40%;text-align: left;">
                        <ul class="pagination  controls" style="margin-left:20px"><li class=" controls" id="FieldSet"></li></ul>
                    </div>
                    <div class="row cs-pagination" style="float:right;width:60%">
                        <ul class="pagination" id="page_nav"></ul>
                        <ul class="pagination controls" id="page_info"></ul>
                        <div style="clear: both;">
                        </div>
                    </div>
                </div>
                
            </div>
        </div>
        <div id="Msg">
        </div>
    </div>
</body>

</html>
